home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
PowerPlant
/
AGA Classes 1.2
/
Sliders
/
LAGAPointedVSlider.cp
< prev
next >
Wrap
Text File
|
1996-06-30
|
18KB
|
615 lines
// ===========================================================================
// LAGAPointedVSlider.cp
// ===========================================================================
// “Apple Grayscale Appearance” compliant pointed vertical slider control
// Copyright © 1996 Chrisoft (Christophe ANDRES) All rights reserved.
//
// You may use this source code in any application (commercial, shareware, freeware,
// postcardware, etc), but not remove this notice (no need to acknowledge the use of
// this class in the about box)
// You may not sell this source code in any form. This source code may be placed on
// publicly accessable archive sites and source code disks. It may not be placed on
// profit archive sites and source code disks without the permission of the author,
// Christophe ANDRES.
//
// This source code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// If you make any change or improvement on this class, please send the improved/changed
// version to : chrisoft@calva.net or Christophe ANDRES
// 20, rue Prosper Mérimée
// 67100 STRASBOURG
// FRANCE
//
// ===========================================================================
// LAGAPointedVSlider.h <- double-click + Command-D to see class declaration
//
// LAGAPointedVSlider is my implementation of the “Apple Grayscale Appearance for System 7.5”
// vertical pointed slider control
//
// This class requires LAGASliderBase.cp to be present in your project
// This class requires AGAColors.cp to be present in your project
//
// Version : 1.2
//
// Change History (most recent first, date in US form : mm/dd/yy):
//
// 06/30/96 ca Public release of version 1.2
// 06/27/96 ca Changed checks for disabled state (check on triState_On instead of triState_Off)
// in order that triState_Latent state is drawn as disabled
// 06/04/96 ca Added RegisterClass method to ease registry
// Increased version to 1.2
// 05/16/96 ca class made available by Christophe ANDRES <chrisoft@calva.net>
// (version 1.1)
//
// To Do:
// A subclass that draws also some labels
//
#include "LAGAPointedVSlider.h"
#include "AGAColors.h"
#include <UDrawingState.h>
#include <PP_Types.h>
// begin <06/04/96 ca>
void LAGAPointedVSlider::RegisterClass ()
{
URegistrar::RegisterClass(LAGAPointedVSlider::class_ID, (ClassCreatorFunc)LAGAPointedVSlider::CreateAGAPointedVSliderStream);
}
// end <06/04/96 ca>
LAGAPointedVSlider* LAGAPointedVSlider::CreateAGAPointedVSliderStream (LStream *inStream)
{
return(new LAGAPointedVSlider(inStream));
}
//-------Constructors-------------------------------------------------------------------------------------------------
LAGAPointedVSlider::LAGAPointedVSlider ()
{
mVerticalSlider = true;
mDrawDivisions = false;
}
LAGAPointedVSlider::LAGAPointedVSlider (LStream *inStream) : LAGASliderBase(inStream)
{
unsigned char theBoolean;
inStream->ReadData(&theBoolean, sizeof(unsigned char));
mDrawDivisions = (theBoolean != 0);
}
LAGAPointedVSlider::LAGAPointedVSlider (const LAGAPointedVSlider &inOriginal) : LAGASliderBase(inOriginal)
{
mDrawDivisions = inOriginal.mDrawDivisions;
}
LAGAPointedVSlider::LAGAPointedVSlider (const SPaneInfo &inPaneInfo, MessageT inValueMessage, Boolean inBottomRightPointer,
Boolean inDrawDivisions, Int32 inInitialValue, Int32 inMinValue, Int32 inMaxValue)
: LAGASliderBase(inPaneInfo, inValueMessage, true, inBottomRightPointer, inInitialValue,
inMinValue, inMaxValue)
{
mDrawDivisions = inDrawDivisions;
}
//-------Drawers----------------------------------------------------------------------------------------------------
void LAGAPointedVSlider::DrawIndicator (Boolean inPushed)
{
StColorPenState theState;
Boolean hasColor = ::PaneInColor(this);
Boolean disabled = (mEnabled != triState_On); // <06/27/96 ca>
Rect frame;
theState.Normalize();
CalcLocalFrameRect(frame);
short position = GetIndicatorPosition();
short origin = (mRightBottomPointing ? frame.left : frame.right - 1);
short direction = (mRightBottomPointing ? 1 : -1);
::SetRect(&frame, (mRightBottomPointing ? origin : origin - 15), position - 7, (mRightBottomPointing ? origin + 15 : origin),
position + 7);
if (hasColor)
::RGBBackColor(&gAGAColorArray[2]);
EraseRect(&frame);
if (hasColor && !disabled)
{
Rect r = frame;
if (mRightBottomPointing)
{
r.left++;
r.right -= 5;
}
else
r.left += 6;
r.top++;
r.bottom++;
::RGBBackColor((inPushed ? &gAGAColorArray[8] : &gAGAColorArray[5]));
::EraseRect(&r);
::RGBForeColor((inPushed ? &gAGAColorArray[8] : &gAGAColorArray[5]));
::MoveTo(origin + (direction * 10), position + 4);
::Line(0, -8);
::Move(direction * 1, 1);
::Line(0, 6);
::Move(direction * 1, -1);
::Line(0, -4);
::Move(direction * 1, 1);
::Line(0, 2);
}
if (disabled)
{
if (hasColor)
::RGBForeColor(&gAGAColorArray[8]);
else
::PenPat(&qd.gray);
}
else
::ForeColor(blackColor);
::MoveTo(origin + (direction * 1), position - 7);
::Line(direction * 8, 0);
if (!hasColor && disabled)
::PenPat(&qd.black);
::Line(direction * 6, 6);
if (!hasColor && disabled)
::PenPat(&qd.gray);
::Line(0, 2);
if (!hasColor && disabled)
::PenPat(&qd.black);
::Line(-(direction * 6), 6);
if (!hasColor && disabled)
::PenPat(&qd.gray);
::Line(-(direction * 8), 0);
::Move(-(direction * 1), -1);
::Line(0, -12);
if (hasColor)
{
if (mRightBottomPointing)
{
::RGBForeColor((disabled ? &gAGAColorArray[1] : (inPushed ? &gAGAColorArray[5] : &gAGAColorArray[3])));
::Move(1, 1); ::Line(0, 10);
::Move(1, -11); ::Line(7, 0);
if (!disabled)
{
::Move(-1, 3); ::Line(-4, 0);
::Move(0, 2); ::Line(4, 0);
::Move(0, 2); ::Line(-4, 0);
}
::RGBForeColor((disabled ? &gAGAColorArray[4] : (inPushed ? &gAGAColorArray[10] : &gAGAColorArray[8])));
::MoveTo(origin + 2, position + 6);
::Line(7, 0);
::Line(5, -5);
::Line(0, -2);
::Line(-4, -4);
::RGBForeColor((disabled ? &gAGAColorArray[W] : (inPushed ? &gAGAColorArray[3] : &gAGAColorArray[1])));
::Move(-9, -1); ::Line(0, 0);
if (!disabled)
{
::Move(2, 3); ::Line(0, 0);
::Move(0, 2); ::Line(0, 0);
::Move(0, 2); ::Line(0, 0);
::RGBForeColor((inPushed ? &gAGAColorArray[12] : &gAGAColorArray[10]));
::Move(1, 1); ::Line(5, 0);
::Move(0, -2); ::Line(-5, 0);
::Move(0, -2); ::Line(5, 0);
}
}
else
{
::RGBForeColor((disabled ? &gAGAColorArray[4] : (inPushed ? &gAGAColorArray[10] : &gAGAColorArray[8])));
::Move(-1, 1); ::Line(0, 11);
::Line(-8, 0);
::Line(-4, -4);
::RGBForeColor((disabled ? &gAGAColorArray[1] : (inPushed ? &gAGAColorArray[5] : &gAGAColorArray[3])));
::Move(-1, -2); ::Line(0, 0);
::Move(1, -2); ::Line(3, -3);
::Move(2, -1); ::Line(6, 0);
if (!disabled)
{
::Move(-2, 3); ::Line(-4, 0);
::Move(0, 2); ::Line(4, 0);
::Move(0, 2); ::Line(-4, 0);
}
::RGBForeColor((disabled ? &gAGAColorArray[W] : (inPushed ? &gAGAColorArray[3] : &gAGAColorArray[1])));
::MoveTo(origin - 14, position - 1);
::Line(0, 0);
::Move(5, -5); ::Line(0, 0);
if (!disabled)
{
::Move(0, 3); ::Line(0, 0);
::Move(0, 2); ::Line(0, 0);
::Move(0, 2); ::Line(0, 0);
::RGBForeColor((inPushed ? &gAGAColorArray[12] : &gAGAColorArray[10]));
::Move(1, 1); ::Line(5, 0);
::Move(0, -2); ::Line(-5, 0);
::Move(0, -2); ::Line(5, 0);
::RGBForeColor((inPushed ? &gAGAColorArray[8] : &gAGAColorArray[5]));
::Move(-11, 3); ::Line(0, 0);
}
}
}
else
if (!disabled)
{
::PenPat(&qd.black);
::Move(direction * 4, 4);
::Line(direction * 5, 0);
::Move(0, 2);
::Line(direction * -5, 0);
::Move(0, 2);
::Line(direction * 5, 0);
}
}
Int16 LAGAPointedVSlider::FindHotSpot (Point inPoint)
{
Rect frame;
// The only hot spot we know of in a slider is the pointer
GetIndicatorRect(frame);
return(::PtInRect(inPoint, &frame) ? 1 : 0);
}
Boolean LAGAPointedVSlider::PointInHotSpot (Point inPoint, Int16 inHotSpot)
{
Rect frame;
// The only hot spot we know of in a slider is the pointer
GetIndicatorRect(frame);
return(::PtInRect(inPoint, &frame));
}
short LAGAPointedVSlider::GetIndicatorPosition ()
{
Rect frame;
CalcLocalFrameRect(frame);
double size = (frame.bottom - frame.top) - 22;
double division = size / (double)(mMaxValue - mMinValue);
return(frame.bottom - 11 - ((mValue - mMinValue) * division));
}
void LAGAPointedVSlider::GetIndicatorRect (Rect &outRect)
{
Rect frame;
CalcLocalFrameRect(frame);
short position = GetIndicatorPosition();
short origin = (mRightBottomPointing ? frame.left : frame.right - 1);
::SetRect(&outRect, (mRightBottomPointing ? origin : origin - 15), position - 7, (mRightBottomPointing ? origin + 16 : origin + 1),
position + 8);
}
void LAGAPointedVSlider::InitializeGhost ()
{
Boolean hasColor = ::PaneInColor(this);
Rect r;
LAGASliderBase::InitializeGhost();
mGhostPointer->BeginDrawing();
if (hasColor)
::RGBBackColor(&gAGAColorArray[2]);
::SetRect(&r, 0, 0, 16, 15);
::EraseRect(&r);
short origin = (mRightBottomPointing ? r.left : r.right - 1);
short direction = (mRightBottomPointing ? 1 : -1);
if (hasColor)
::RGBForeColor(&gAGAColorArray[7]);
::MoveTo(origin + (direction * 1), 0);
::Line(direction * 8, 0);
::Line(direction * 6, 6);
::Line(0, 2);
::Line(direction * -6, 6);
::Line(direction * -8, 0);
::Move(direction * -1, -1);
::Line(0, -12);
::Move(direction * 4, 12);
::Line(0, 0);
::Move(direction * 4, 0);
::Line(0, 0);
if (hasColor)
{
if (mRightBottomPointing)
{
::RGBForeColor(&gAGAColorArray[5]);
::Move(0, -1); ::Line(0, -2);
::Move(-4, 0); ::Line(0, 2);
::Move(1, -3); ::Line(2, 0);
::Move(2, 0); ::Line(0, 0);
::Move(0, -2); ::Line(0, 0);
::Move(-2, 0); ::Line(-2, 0);
::Move(0, -2); ::Line(2, 0);
::Move(2, 0); ::Line(0, 0);
::Move(-1, -2); ::Line(0, -1);
::Move(-4, 0); ::Line(0, 1);
::RGBForeColor(&gAGAColorArray[4]);
::Move(6, -1); ::Line(4, 4);
::Line(0, 2); ::Line(-5, 5);
::Move(-2, 0); ::Line(-2, 0);
::Move(-2, 0); ::Line(-1, 0);
::RGBForeColor(&gAGAColorArray[11]);
::Move(2, 1); ::Line(0, 0);
::Move(4, 0); ::Line(0, 0);
::Move(0, -14); ::Line(0, 0);
::Move(-4, 0); ::Line(0, 0);
::RGBForeColor(&gAGAColorArray[1]);
::Move(-3, 1); ::Line(0, 0);
::RGBForeColor(&gAGAColorArray[9]);
::Move(3, 4); ::Line(0, 0);
::Move(4, 0); ::Line(0, 0);
::Move(0, 2); ::Line(0, 0);
::Move(-4, 0); ::Line(0, 0);
::Move(0, 2); ::Line(0, 0);
::Move(4, 0); ::Line(0, 0);
::ForeColor(whiteColor);
::Move(-1, -1); ::Line(-2, 0);
::Move(-2, 0); ::Line(0, 0);
::Move(0, -2); ::Line(0, 0);
::Move(2, 0); ::Line(2, 0);
::Move(0, -2); ::Line(-2, 0);
::Move(-2, 0); ::Line(0, 0);
::Move(6, -3); ::Line(0, 0);
::Move(-2, 0); ::Line(-2, 0);
::Move(-2, 0); ::Line(-1, 0);
::Move(-1, 1); ::Line(0, 10);
}
else
{
::RGBForeColor(&gAGAColorArray[5]);
::Move(0, -1); ::Line(0, -2);
::Move(4, 0); ::Line(0, 2);
::Move(1, -3); ::Line(0, 0);
::Move(-2, 0); ::Line(-2, 0);
::Move(0, -2); ::Line(2, 0);
::Move(2, 0); ::Line(0, 0);
::Move(0, -2); ::Line(0, 0);
::Move(-2, 0); ::Line(-2, 0);
::Move(-1, -2); ::Line(0, -1);
::Move(4, 0); ::Line(0, 1);
::RGBForeColor(&gAGAColorArray[4]);
::Move(3, -1); ::Line(0, 11);
::Line(-2, 0);
::Move(-2, 0); ::Line(-2, 0);
::Move(-2, 0); ::Line(-4, -4);
::RGBForeColor(&gAGAColorArray[1]);
::Move(-1, -2); ::Line(0, 0);
::RGBForeColor(&gAGAColorArray[9]);
::Move(6, 2); ::Line(0, 0);
::Move(4, 0); ::Line(0, 0);
::Move(0, -2); ::Line(0, 0);
::Move(-4, 0); ::Line(0, 0);
::Move(0, -2); ::Line(0, 0);
::Move(4, 0); ::Line(0, 0);
::RGBForeColor(&gAGAColorArray[11]);
::Move(0, -5); ::Line(0, 0);
::Move(-4, 0); ::Line(0, 0);
::Move(0, 14); ::Line(0, 0);
::Move(4, 0); ::Line(0, 0);
::ForeColor(whiteColor);
::Move(-1, -6); ::Line(-2, 0);
::Move(-2, 0); ::Line(0, 0);
::Move(0, -2); ::Line(0, 0);
::Move(2, 0); ::Line(2, 0);
::Move(0, -2); ::Line(-2, 0);
::Move(-2, 0); ::Line(0, 0);
::Move(-5, 2); ::Line(5, -5);
::Move(2, 0); ::Line(2, 0);
::Move(2, 0); ::Line(1, 0);
}
}
mGhostPointer->EndDrawing();
// Define a region to draw the pointer nicely if the ghost passes on its top
mGhostMask = ::NewRgn();
::OpenRgn();
::MoveTo(origin + (direction * 1), 0);
::Line(direction * 8, 0);
::Line(direction * 6, 6);
::Line(0, 2);
::Line(direction * -6, 6);
::Line(direction * -8, 0);
::Line(direction * -1, -1);
::Line(0, -12);
::Line(direction * 1, -1);
::CloseRgn(mGhostMask);
}
void LAGAPointedVSlider::DrawGhost (Point inPoint)
{
Rect frame;
short position;
if (inPoint.v != mLastPosition.v)
{
Rect indicRect, overStep;
CalcLocalFrameRect(frame);
double size = (frame.bottom - frame.top) - 22;
double division = size / (double)(mMaxValue - mMinValue);
short MaxPt = frame.bottom - 11 - ((mMaxValue - mMinValue) * division);
short MinPt = frame.bottom - 11;
short origin = (mRightBottomPointing ? frame.left : frame.right - 1);
if (inPoint.v < MaxPt)
position = MaxPt;
else
if (inPoint.v > MinPt)
position = MinPt;
else
position = inPoint.v;
frame.left = (mRightBottomPointing ? origin : origin - 15);
frame.right = frame.left + 16;
frame.top = position - 7;
frame.bottom = frame.top + 15;
if (!::EmptyRect(&mLastGhost))
{
indicRect = mLastGhost;
StClipRgnState clip;
if (indicRect.top < frame.top)
{
if (indicRect.bottom > frame.top)
indicRect.bottom = frame.top;
}
else
{
if (frame.bottom > indicRect.top)
indicRect.top = frame.bottom;
}
clip.ClipToIntersection(indicRect);
::RGBBackColor(&gAGAColorArray[2]);
::EraseRect(&mLastGhost);
DrawSlideTrack();
GetIndicatorRect(indicRect);
if (::SectRect(&indicRect, &mLastGhost, &overStep))
DrawIndicator(true);
}
StColorPenState theState;
theState.Normalize();
mGhostPointer->CopyImage(GetMacPort(), frame);
if ((!::EmptyRect(&overStep)) && (mGhostMask != nil))
{
StClipRgnState clip;
::OffsetRgn(mGhostMask, -(*mGhostMask)->rgnBBox.left, -(*mGhostMask)->rgnBBox.top);
::OffsetRgn(mGhostMask, frame.left, frame.top);
RgnHandle theClipRegion = ::NewRgn();
GetIndicatorRect(indicRect);
::RectRgn(theClipRegion, &indicRect);
::DiffRgn(theClipRegion, mGhostMask, theClipRegion);
clip.ClipToIntersectionRgn(theClipRegion);
DrawIndicator(true);
}
mLastGhost = frame;
mLastPosition = inPoint;
}
}
void LAGAPointedVSlider::FinishTrackHotSpot (Point inPoint)
{
Boolean hasColor = ::PaneInColor(this);
Rect frame, indicRect;
short newValue;
CalcLocalFrameRect(frame);
double size = (frame.bottom - frame.top) - 22;
double division = size / (double)(mMaxValue - mMinValue);
short MaxPt = frame.bottom - 11 - ((mMaxValue - mMinValue) * division);
short MinPt = frame.bottom - 11;
if (inPoint.v <= MaxPt)
newValue = mMaxValue;
else
if (inPoint.v >= MinPt)
newValue = mMinValue;
else
{
newValue = ((MinPt - inPoint.v) / division) + mMinValue;
short lowPos = frame.bottom - 11 - (newValue * division);
short highPos = frame.bottom - 11 - ((newValue + 1) * division);
if ((lowPos - inPoint.v) > (inPoint.v - highPos))
newValue++;
}
if (newValue != mValue)
{
StClipRgnState clip;
clip.Normalize();
GetIndicatorRect(indicRect);
if (hasColor)
::RGBBackColor(&gAGAColorArray[2]);
::EraseRect(&indicRect);
::EraseRect(&mLastGhost);
DrawSlideTrack();
// Update our control value and Broadcast it
SetValue(newValue);
}
else
{
if (hasColor)
::RGBBackColor(&gAGAColorArray[2]);
::EraseRect(&mLastGhost);
DrawSlideTrack();
}
// We dont redraw the pointer here, because it will anyway be redrawn in the unpressed state
// in the method LAGASliderBase::HotSpotResult
}
void LAGAPointedVSlider::DrawLabels ()
{
if (mDrawDivisions)
{
StColorPenState theState;
Boolean hasColor = ::PaneInColor(this);
Boolean disabled = (mEnabled != triState_On); // <06/27/96 ca>
Rect frame;
CalcLocalFrameRect(frame);
double size = (frame.bottom - frame.top) - 22;
double division = size / (double)(mMaxValue - mMinValue);
short step = 1;
if (division < 4)
step = 2;
short origin = (mRightBottomPointing ? frame.left : frame.right - 1);
short direction = (mRightBottomPointing ? 1 : -1);
short position;
for (int i = mMinValue; i <= mMaxValue; i += step)
{
position = frame.bottom - 11 - ((i - mMinValue) * division);
if (hasColor)
::RGBForeColor((disabled ? &gAGAColorArray[8] : &gAGAColorArray[B]));
else
if (disabled)
::PenPat(&qd.gray);
::MoveTo(origin + (direction * 17), position);
::Line(direction * 5, 0);
if (hasColor)
{
if (!mRightBottomPointing)
::Move(5, 0);
::RGBForeColor((disabled ? &gAGAColorArray[4] : &gAGAColorArray[7]));
::Move(1, 0);
::Line(0, 1);
::Line(-6, 0);
::ForeColor(whiteColor);
::Move(-1, -1);
::Line(0, -1);
::Line(6, 0);
}
}
}
}